import {
  CategoryCreateDto,
  CategoryFindDto,
  CategoryListDto,
  CategoryQueryDto,
  CategoryRemoveDto,
  CategoryUpdateDto,
} from '@/dtos';
import { CategoryService } from '@/services/category.service';
import { ok } from '@/utils';
import { Body, Controller, Delete, Patch, Post, Query } from '@nestjs/common';
import { BaseController } from './base.controller';

@Controller('category')
export class CategoryController extends BaseController {
  constructor(private readonly categoryService: CategoryService) {
    super();
  }

  @Post('list')
  async getList(@Body() dto: CategoryListDto) {
    return ok(await this.categoryService.list(dto));
  }

  @Post('admin/query')
  async query(@Body() dto: CategoryQueryDto) {
    return ok(await this.categoryService.query(dto));
  }

  @Post('admin/find')
  async find(@Body() dto: CategoryFindDto) {
    return ok(await this.categoryService.findOne(dto.where, dto.select));
  }

  @Post('admin/create')
  async create(@Body() dto: CategoryCreateDto) {
    return ok(await this.categoryService.create(dto.data));
  }

  @Patch('admin/update')
  async update(@Body() dto: CategoryUpdateDto) {
    return ok(await this.categoryService.update(dto));
  }

  @Delete('admin/remove')
  async remove(@Query() dto: CategoryRemoveDto) {
    return ok(await this.categoryService.remove(dto));
  }
}
